<template>
  <div class="dashboard-editor-container">
    <PanelGroup @handleSetLineChartData="handleSetLineChartData"/>

    <div class="chart-line">
      <line-chart :chart-data="lineChartData" :yTittle="yTitle"/>
    </div>

    <el-row :gutter="20" class="chart-row">
      <el-col :xs="24" :sm="24" :lg="12">
        <el-card>
          <bar-chart />
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="12">
        <el-card>
          <pie-chart />
        </el-card>
      </el-col>
    </el-row>

    <!-- <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :lg="8">
        <el-card>
          <line-chart2 />
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <el-card>
          <bar-chart2 />
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <el-card>
          <pie-chart2/>
        </el-card>
      </el-col>
    </el-row> -->
  </div>
</template>

<script>
import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'
import BarChart from './components/BarChart'
import PieChart from './components/PieChart'

// import LineChart2 from './components/LineChart2'
// import BarChart2 from './components/BarChart2'
// import PieChart2 from './components/PieChart2'

const lineChartDatas = {
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130]
  },
  shoppings: {
    expectedData: [1300, 1400, 1410, 1402, 1405, 1500, 1600],
    actualData: [1200, 820, 910, 1504, 1602, 1400, 1218]
  },
  newUsers: {
    expectedData: [6552, 6663, 7252, 7654, 7912, 8240, 8341],
    actualData: [6752, 6863, 7352, 7554, 8012, 8440, 8641]
  },
  messages: {
    expectedData: [20100, 19230, 12700, 14410, 16500, 13030, 14050],
    actualData: [18500, 16040, 15160, 10650, 14540, 15300, 13200]
  }
}

const yTitles = {
  purchases: '交易金额(万元)',
  shoppings: '订单数量(个)',
  newUsers: '客户数量(人)',
  messages: '库存数量(条)'
}

export default {
  name: 'DashBoard',

  data () {
    return {
      lineChartDatas: [],
      // lineChartData: lineChartDatas.purchases,
      lineChartData: {},
      yTitle: yTitles.purchases,
      timer: null
    }
  },

  mounted () {
    this.timer = setTimeout(() => {
      this.lineChartDatas = lineChartDatas
      this.lineChartData = lineChartDatas.purchases
    }, 1000)
  },
  destroyed () {
    clearTimeout(this.timer)
  },
  methods: {
    handleSetLineChartData (type) {
      this.yTitle = yTitles[type]
      this.lineChartData = lineChartDatas[type]
    }
  },

  components: {
    PanelGroup,
    LineChart,
    BarChart,
    PieChart,
    // LineChart2,
    // BarChart2,
    // PieChart2
  }
}
</script>

<style lang="less" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  .chart-line {
    background:#fff;
    padding:16px 0 0 16px;
    margin-bottom:32px;
  }
  .chart-row {
    margin-bottom: 32px;
  }
}
</style>
